#ifndef __FactorManager_INL__
#define __FactorManager_INL__

template<class ProductType, class ClassFactor>
FactorManager<ProductType, ClassFactor>::FactorManager(void)
{
  mCurclass = NULL;
}

template<class ProductType, class ClassFactor>
FactorManager<ProductType, ClassFactor>::~FactorManager(void)
 {
	DeleteData();
 }


template<class ProductType, class ClassFactor>
void FactorManager<ProductType, ClassFactor>::DeleteData()
 {
   if (mCurclass != NULL)
   {

     mCurclass = NULL;
   }


   std::map<ProductType, ClassFactor *>::iterator it = mmapclass.begin();

   if ( it != mmapclass.end())
   {
     for(;it!= mmapclass.end(); it++)
     {
		 ClassFactor *pclass = it->second;
     
       if (pclass != NULL)
       {
		   FactorManagerBase<ProductType, ClassFactor>::destroy(it->first, pclass, 0);
 
       }
     }

 
     mmapclass.clear();
   }
 }

template<class ProductType, class ClassFactor>
ClassFactor* FactorManager<ProductType, ClassFactor>::Get(const ProductType& type) const
 {

	ClassFactor* pCreator = NULL;

	std::map<ProductType, ClassFactor*>::const_iterator it = mmapclass.find(type);
	 if (it != mmapclass.end())
	 {
		 pCreator = it->second;
	 }

	 return pCreator;
 }


template<class ProductType, class ClassFactor>
ClassFactor * FactorManager<ProductType, ClassFactor>::Create(ProductType type, void* pData, bool blnChange)
{
	std::map<ProductType, ClassFactor *> ::iterator it = mmapclass.find(type);

	ClassFactor *pclass = NULL;
  if (it == mmapclass.end())
  {
    {
      pclass = _Creat(type, pData);
    }
    if (pclass !=NULL)
    {
      mmapclass[type] = pclass;
    
    }
  }
  else
  {

    pclass = mmapclass[type];
  }

  if (blnChange)
  {
    mCurclass = pclass;
  }

  return pclass;
}


template<class ProductType, class ClassFactor>
ClassFactor * FactorManager<ProductType, ClassFactor>::_Creat(ProductType type, void* pData)
{
	ClassFactor *pClass = FactorManagerBase<ProductType, ClassFactor>::_Creat(type, pData);
  return pClass;
}



template<class ProductType, class ClassFactor>
BOOL FactorManager<ProductType, ClassFactor>::Regisit(ProductType type, ClassFactor *pclass, bool blnChange)
{
  BOOL blnReturn = FALSE;

  std::map<ProductType, ClassFactor *> ::iterator it = mmapclass.find(type);
  if (it == mmapclass.end())
  {


    if (pclass !=NULL)
    {
      mmapclass[type] = pclass;

      blnReturn = TRUE;
    }
  }
  else
  {

    if (pclass && pclass != it->second)
    {

      delete pclass; pclass = NULL;
    }
  }

  if (blnChange && blnReturn)
  {
    mCurclass = pclass;
  }

  return blnReturn;
}


#endif